package visao;

import Controlador.GeremciaPessoas;
import Controlador.GerenciarClasse;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
import modelo.Classe;
import modelo.Pessoas;
import util.Hora;
import util.ValidaCnpj;
import util.ValidaCpf;
import modelo.JCalendar;
import java.util.GregorianCalendar;
/**
 *
 * @author Ronaldo
 */
public class CadastroDePessoas extends javax.swing.JFrame {

    GeremciaPessoas pss = new GeremciaPessoas();
    GerenciarClasse cla = new GerenciarClasse();
    Vector<Classe> dados;
    DefaultComboBoxModel modelo = null;

    public CadastroDePessoas() {
        initComponents();
        AprentaData();
        ApresentaClasse();
        codigo();
        fisicaJuridica();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jbGravar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jlCodigo = new javax.swing.JLabel();
        jtCodigo = new javax.swing.JTextField();
        jlTipo = new javax.swing.JLabel();
        jcTipo = new javax.swing.JComboBox();
        jlNome = new javax.swing.JLabel();
        jtNome = new javax.swing.JTextField();
        jlApelido = new javax.swing.JLabel();
        jtApelido = new javax.swing.JTextField();
        jlCpf = new javax.swing.JLabel();
        jftCpf = new javax.swing.JFormattedTextField();
        jlRg = new javax.swing.JLabel();
        jtRg = new javax.swing.JTextField();
        jlDataNacimento = new javax.swing.JLabel();
        jftDataNacimento = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        jlOrgao = new javax.swing.JLabel();
        jtOrgaoExpedidor = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jtEndereco = new javax.swing.JTextField();
        jftCep = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        jtNumero = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jtComplemento = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jtBairro = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jtCidade = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jtCodigoCidade = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jtEstado = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jtCaixaPostal = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jtPontoReferencia = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jftFoneResidencia = new javax.swing.JFormattedTextField();
        jLabel20 = new javax.swing.JLabel();
        jftFoneComercio = new javax.swing.JFormattedTextField();
        jLabel21 = new javax.swing.JLabel();
        jftCelular = new javax.swing.JFormattedTextField();
        jLabel22 = new javax.swing.JLabel();
        jtContato = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jtEmail = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jftDataCadastro = new javax.swing.JFormattedTextField();
        jlClasse = new javax.swing.JLabel();
        jcbClasse = new javax.swing.JComboBox();
        ccb = new modelo.JCalendar(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro De Pessoas");

        jbGravar.setText("Gravar");
        jbGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGravarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbGravar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 14, Short.MAX_VALUE)
                .addComponent(jbGravar))
        );

        jlCodigo.setText("Codigo");

        jlTipo.setText("Tipo");

        jcTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Fisica", "Juridica" }));
        jcTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcTipoActionPerformed(evt);
            }
        });

        jlNome.setText("Nome");

        jlApelido.setText("Apelido");

        jlCpf.setText("Cpf");

        jftCpf.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jftCpfFocusLost(evt);
            }
        });

        jlRg.setText("Rg");

        jlDataNacimento.setText("Data de Nacimento");

        jftDataNacimento.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jftDataNacimentoFocusGained(evt);
            }
        });

        jLabel8.setText("Cep");

        jlOrgao.setText("Orgao Expedidor");

        jLabel10.setText("Endereco");

        jftCep.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jftCepFocusGained(evt);
            }
        });

        jLabel11.setText("Numero");

        jLabel12.setText("Complemento");

        jLabel13.setText("Bairro");

        jLabel14.setText("Cidade");

        jLabel15.setText("Codigo Cidade");

        jLabel16.setText("Estado");

        jLabel17.setText("Caixa Postal");

        jLabel18.setText("Ponto Referencia");

        jLabel19.setText("Fone Residencia");

        jftFoneResidencia.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jftFoneResidenciaFocusGained(evt);
            }
        });

        jLabel20.setText("Fone Comercio");

        jftFoneComercio.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jftFoneComercioFocusGained(evt);
            }
        });

        jLabel21.setText("Celular");

        jftCelular.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jftCelularFocusGained(evt);
            }
        });

        jLabel22.setText("Contato");

        jLabel23.setText("e-Mail");

        jLabel24.setText("Data Cadastro");

        jlClasse.setText("Classe");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlOrgao)
                            .addComponent(jLabel11)
                            .addComponent(jLabel13)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlCodigo)
                                    .addComponent(jlNome)
                                    .addComponent(jlCpf)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel21))
                                .addGap(17, 17, 17)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtNome)
                                    .addComponent(jftCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jlTipo)
                                        .addGap(18, 18, 18)
                                        .addComponent(jcTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(30, 30, 30))
                                    .addComponent(jtBairro)
                                    .addComponent(jtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                                    .addComponent(jtOrgaoExpedidor, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtNumero, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                                    .addComponent(jftCep)
                                    .addComponent(jtCaixaPostal, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .addComponent(jtCodigoCidade)
                                    .addComponent(jftCelular, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                                    .addComponent(jftFoneResidencia)))
                            .addComponent(jLabel23))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlRg)
                                            .addComponent(jlApelido))
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlDataNacimento)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel12)
                                            .addComponent(jLabel14)
                                            .addComponent(jLabel16)
                                            .addComponent(jLabel18)
                                            .addComponent(jLabel20)
                                            .addComponent(jLabel22)
                                            .addComponent(jLabel24))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jtEndereco)
                                            .addComponent(jtComplemento)
                                            .addComponent(jtCidade)
                                            .addComponent(jtEstado)
                                            .addComponent(jtPontoReferencia)
                                            .addComponent(jtContato)
                                            .addGroup(jPanel2Layout.createSequentialGroup()
                                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jftFoneComercio, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jftDataNacimento, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(ccb, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(0, 151, Short.MAX_VALUE)))))
                                .addGap(46, 46, 46))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jlClasse)
                                        .addGap(74, 74, 74)
                                        .addComponent(jcbClasse, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jtRg, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jtApelido, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(93, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jftDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlCodigo)
                    .addComponent(jtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlTipo)
                    .addComponent(jcTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlClasse)
                    .addComponent(jcbClasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlNome)
                    .addComponent(jtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlApelido)
                    .addComponent(jtApelido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlCpf)
                    .addComponent(jftCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlRg)
                    .addComponent(jtRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtOrgaoExpedidor)
                    .addComponent(jlDataNacimento)
                    .addComponent(jftDataNacimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlOrgao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10)
                    .addComponent(jtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jftCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(jtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtCodigoCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16)
                    .addComponent(jtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jtCaixaPostal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtPontoReferencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jftFoneResidencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20)
                    .addComponent(jftFoneComercio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jftCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22)
                    .addComponent(jtContato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(ccb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(59, 59, 59)
                .addComponent(jftDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Cadastro", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 15, Short.MAX_VALUE))
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void jbGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGravarActionPerformed
        gravar();
    }//GEN-LAST:event_jbGravarActionPerformed

    private void jftCpfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftCpfFocusLost
        ApresentaCpf();
    }//GEN-LAST:event_jftCpfFocusLost

    private void jftDataNacimentoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftDataNacimentoFocusGained
        try {
            jftDataNacimento.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
        }
    }//GEN-LAST:event_jftDataNacimentoFocusGained

    private void jftCepFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftCepFocusGained
        try {
            jftCep.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
        }
    }//GEN-LAST:event_jftCepFocusGained

    private void jftFoneResidenciaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftFoneResidenciaFocusGained
//        try {
//            jftFoneResidencia.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("(##)####-####")));
//        } catch (java.text.ParseException ex) {
//        }
    }//GEN-LAST:event_jftFoneResidenciaFocusGained

    private void jftCelularFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftCelularFocusGained
        try {
            jftCelular.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
        }
    }//GEN-LAST:event_jftCelularFocusGained

    private void jftFoneComercioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftFoneComercioFocusGained
        try {
            jftFoneComercio.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
        }
    }//GEN-LAST:event_jftFoneComercioFocusGained

    private void jcTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcTipoActionPerformed
        fisicaJuridica();
    }//GEN-LAST:event_jcTipoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroDePessoas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new CadastroDePessoas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ccb;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jbGravar;
    private javax.swing.JComboBox jcTipo;
    private javax.swing.JComboBox jcbClasse;
    private javax.swing.JFormattedTextField jftCelular;
    private javax.swing.JFormattedTextField jftCep;
    private javax.swing.JFormattedTextField jftCpf;
    private javax.swing.JFormattedTextField jftDataCadastro;
    private javax.swing.JFormattedTextField jftDataNacimento;
    private javax.swing.JFormattedTextField jftFoneComercio;
    private javax.swing.JFormattedTextField jftFoneResidencia;
    private javax.swing.JLabel jlApelido;
    private javax.swing.JLabel jlClasse;
    private javax.swing.JLabel jlCodigo;
    private javax.swing.JLabel jlCpf;
    private javax.swing.JLabel jlDataNacimento;
    private javax.swing.JLabel jlNome;
    private javax.swing.JLabel jlOrgao;
    private javax.swing.JLabel jlRg;
    private javax.swing.JLabel jlTipo;
    private javax.swing.JTextField jtApelido;
    private javax.swing.JTextField jtBairro;
    private javax.swing.JTextField jtCaixaPostal;
    private javax.swing.JTextField jtCidade;
    private javax.swing.JTextField jtCodigo;
    private javax.swing.JTextField jtCodigoCidade;
    private javax.swing.JTextField jtComplemento;
    private javax.swing.JTextField jtContato;
    private javax.swing.JTextField jtEmail;
    private javax.swing.JTextField jtEndereco;
    private javax.swing.JTextField jtEstado;
    private javax.swing.JTextField jtNome;
    private javax.swing.JTextField jtNumero;
    private javax.swing.JTextField jtOrgaoExpedidor;
    private javax.swing.JTextField jtPontoReferencia;
    private javax.swing.JTextField jtRg;
    // End of variables declaration//GEN-END:variables

    private void gravar() {
        String cod = jtCodigo.getText().toUpperCase();;
        Object tipo = jcTipo.getSelectedItem();
        Object classeloc = jcbClasse.getSelectedItem();
        String nome = jtNome.getText().toUpperCase();;
        String apel = jtApelido.getText();
        String cpf = jftCpf.getText();
        String rg = jtRg.getText();
        String orgao = jtOrgaoExpedidor.getText();
        String nacimento = jftDataNacimento.getText();
        String cep = jftCep.getText();
        String end = jtEndereco.getText();
        String num = jtNumero.getText();
        String complemento = jtComplemento.getText();
        String bairro = jtBairro.getText();
        String cidade = jtCidade.getText();
        String cCidade = jtCodigoCidade.getText();
        String estado = jtEstado.getText();
        String cPostal = jtCaixaPostal.getText();
        String pReferencia = jtPontoReferencia.getText();
        String fResidencia = jftFoneResidencia.getText();
        String fComercio = jftFoneComercio.getText();
        String celular = jftCelular.getText();
        String contato = jtContato.getText();
        String email = jtEmail.getText();
        String dCadastro = jftDataCadastro.getText();

//        Pessoas pe = pss.localizarCodigo(cod);
//        if (pe!=null) {
//            JOptionPane.showMessageDialog(this, "Codigo ja Esta Cadastrado!!!");
//        }
//        Pessoas pes = pss.localizarCpf(cpf);
//        if (pes!=null) {
//            JOptionPane.showMessageDialog(this, "Cpf/Cnpj ja Esta Cadastrado!!!");
//        }

        Pessoas pessoas = new Pessoas(Integer.parseInt(cod), String.valueOf(tipo),
                String.valueOf(classeloc), nome, apel, cpf, rg, orgao, nacimento,
                cep, end, Integer.parseInt(num), complemento, bairro, cidade,
                Integer.parseInt(cCidade), estado, cPostal, pReferencia,
                fResidencia, fComercio, celular, contato, email, dCadastro);
        boolean resp = pss.gravarPessoas(pessoas);
        if (resp) {
            JOptionPane.showMessageDialog(this, "Gravado com sucesso!!!");
            // limpaTela();

        } else {
            JOptionPane.showMessageDialog(this, "Erro ao gravar!!!");
        }


        codigo();


    }

    private void ApresentaCpf() {
        String CPF = jftCpf.getText();
        Object tipo = jcTipo.getSelectedItem();


        if (tipo == "Fisica") {
            if (!CPF.equals("")) {
                if (ValidaCpf.isCPF(CPF) == true) {
                    jftCpf.setText(ValidaCpf.imprimeCPF(CPF));
                } else {
                    JOptionPane.showMessageDialog(this, "Erro, CPF invalido !!!");
                    jftCpf.requestFocus();
                }
            }
        } else {
            if (!CPF.equals("")) {
                if (ValidaCnpj.isCNPJ(CPF) == true) {
                    jftCpf.setText(ValidaCnpj.imprimeCNPJ(CPF));
                } else {
                    JOptionPane.showMessageDialog(this, "Erro, CNPJ invalido !!!");
                    jftCpf.requestFocus();
                }
            }
        }
    }

    private void AprentaData() {

        Hora mostra_data;
        mostra_data = new Hora();
        mostra_data.le_data();
        jftDataCadastro.setText(mostra_data.dia + "/" + mostra_data.mes + "/" + mostra_data.ano);
    }

    private void limpaTela() {
        jtCodigo.setText("");
        jcTipo.setSelectedItem("");
        jcbClasse.setSelectedItem("");
        jtNome.setText("");
        jtApelido.setText("");
        jftCpf.setText("");
        jtRg.setText("");
        jtOrgaoExpedidor.setText("");
        jftDataNacimento.setText("");
        jftCep.setText("");
        jtEndereco.setText("");
        jtNumero.setText("");
        jtComplemento.setText("");
        jtBairro.setText("");
        jtCidade.setText("");
        jtCodigoCidade.setText("");
        jtEstado.setText("");
        jtCaixaPostal.setText("");
        jtPontoReferencia.setText("");
        jftFoneResidencia.setText("");
        jftFoneComercio.setText("");
        jftCelular.setText("");
        jtContato.setText("");
        jtEmail.setText("");

    }

    private void ApresentaClasse() {
        dados = new Vector<Classe>();
        modelo = new DefaultComboBoxModel(dados);
        // dados.removeAllElements();
        List<Classe> lista = cla.localizarTodos();
        for (Classe disciplina : lista) {
            dados.add(disciplina);
        }
        jcbClasse.setModel(modelo);
    }

    private void codigo() {
        int ultimoCodigo = pss.localizarUltimoCodigo();
        jtCodigo.setText(ultimoCodigo + 1 + "");
    }

    private void fisicaJuridica() {
        Object tipo = jcTipo.getSelectedItem();
        if (tipo != "Fisica") {
            jlNome.setText("Razao Social");
            jlApelido.setText("Fantasia");
            jlRg.setText("I.E.");
            jlCpf.setText("Cnpj");
        } else {
            jlNome.setText("Nome");
            jlApelido.setText("Apelido");
            jlRg.setText("R.G.");
            jlCpf.setText("Cpf");
        }
    }

    public String imprimetel(String fResidencia) {
        String tel = jftFoneResidencia.getText();
        // máscara do CNPJ: 99.999.999.9999-99
        return (tel.substring(0, 0) + "(" + tel.substring(2, 2) + ")"
                + tel.substring(8, 8) + "-" + tel.substring(8, 12));
    }
}
